package com.cjg.cas;

import java.util.concurrent.atomic.AtomicInteger;
//CAS compareAndSet : 比较并交换!
public class demo01 {
    public static void main(String[] args) {
        // 期望到了就更新 , 不然就不更新 .CAS是 cpu的并发语句
        System.out.println("=======================扰乱=========================");
        AtomicInteger atomicInteger = new AtomicInteger(2020);
        boolean b = atomicInteger.compareAndSet(2020, 2000);

        atomicInteger.compareAndSet(2000, 2020);
        System.out.println("================扰乱================");
        boolean a = atomicInteger.compareAndSet(2020, 20);
        System.out.println(a);
        System.out.println(atomicInteger.get());
    }
}
